import 'package:acgn_pioneer/components/custom_pageview.dart';
import 'package:acgn_pioneer/pages/sort/sort_catalog_page.dart';
import 'package:acgn_pioneer/pages/sort/sort_result_page.dart';
import 'package:flutter/widgets.dart';
import '../../public.dart';

/// 分类页
class SortMainPage extends StatefulWidget {
  SortMainPage({Key key}) : super(key: key);

  @override
  SortMainPageState createState() => SortMainPageState();
}

class SortMainPageState extends State<SortMainPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  ScrollController _scrollController = ScrollController();
  var screenWidth = ScreenUtil.getInstance().screenWidth;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: 2);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: ColorUtil.rgba(27, 27, 38, 1),
        appBar: AppBar(
            backgroundColor: ColorUtil.rgba(27, 27, 38, 1),
            title: Padding(
              padding: EdgeInsets.only(left: 10, right: 30),
              child: TabBar(
                  indicator: const BoxDecoration(),
                  controller: this._tabController,
                  labelColor: Colors.white,
                  unselectedLabelColor: ColorUtil.rgba(255, 255, 255, 0.6),
                  labelStyle: TextStyle(fontSize: 18),
                  tabs: <Widget>[
                    Tab(text: '搜索'),
                    Tab(text: '分类'),
                  ]),
            ),
            leadingWidth: 44,
            leading: BackComponent(),
            centerTitle: true),
        body: CustomPageview(
          tabController: _tabController,
          controller: _scrollController,
          children: [SortResultPage(), SortCatalogPage()],
          onChange: (int page) {
            _tabController.animateTo(page);
          },
        ));
  }
}
